HitTest Method

The HitTest method returns the graphics elements at a specific location or within a defined box.

Example

The MouseDownDeleteRight function uses a mouse event function to define the mouse button action.

FUNCTION MOUSEDOWNDELETERIGHT, Window, $

X, Y, Button, KeyMods, Clicks

 

PRINT, 'MouseDownHandler'

HELP, Window, $

   X, Y, Button, KeyMods, Clicks

 

IF Button EQ 4 THEN BEGIN

  oVisList = Window.HitTest(X, Y)

  FOREACH vis, oVisList DO BEGIN

    vis.Delete

  ENDFOREACH

  RETURN, 0 ; Skip default event handling

ENDIF ELSE RETURN, 1 ; Perform default event handling

 

END

The DeleteRight routine creates a graphic with text areas to test the MouseDownDeleteRight function.

PRO DELETERIGHT

; Delete a graphic if the user right-clicks on it

p=plot(/test)

t1=text(.5, .8, 'Text 1')

t2=text(.5, .5, 'Text 2')

p.window.MOUSE_DOWN_HANDLER='MouseDownDeleteRight'

 

HELP, p, t1, t2

 

END

Syntax

Result = graphic.HitTest(X, Y, [DIMENSIONS=dimensions])

Return Value

The HitTest method returns an array of graphics items at a specified location or within a box specified by dimensions. Use the returned references to manipulate the graphics.

Arguments

X

The X location, in device coordinates, to use for the hit test.

Y

The Y location, in device coordinates, to use for the hit test.

Keywords

DIMENSIONS

A two element vector [X,Y] containing the dimensions of a box centered on X, Y to use for the hit test.

Version History

8.1

Introduced

See Also

Select Method, Using IDL Graphics